﻿using EMall.IdentityService.Roles;
using EMall.Query;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;

namespace EMall.IdentityService.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RoleController : ControllerBase
    {
        private readonly IRoleAppService _roleAppService;
        public RoleController(IRoleAppService roleAppService)
        {
            _roleAppService = roleAppService;
        }
        [HttpPost]
        public async Task CreateAsync(CreateRoleDto input)
        {
            await _roleAppService.CreateAsync(input);
        }
        [HttpPut]
        public async Task UpdateAsync(UpdateRoleDto input)
        {
            await _roleAppService.UpdateAsync(input);
        }
        [HttpDelete]
        public async Task DeleteAsync(DeleteRoleDto input)
        {
            await _roleAppService.DeleteAsync(input);
        }
        [HttpGet]
        public async Task<RoleDto> GetAsync(int id)
        {
            return await _roleAppService.GetAsync(id);
        }
        [HttpGet]
        public async Task<IEnumerable<RoleListDto>> GetListAsync([FromQuery] GetRoleListQueryDto input)
        {
            return await _roleAppService.GetListAsync(input);
        }
        [HttpGet]
        public async Task<IPagedList<RoleListDto>> GetPagedListAsync([FromQuery] GetRoleListPagingAndSortingQueryDto input)
        {
            return await _roleAppService.GetPagedListAsync(input);
        }
    }
}
